package com.jcfk.eam.enums;

import java.util.HashMap;
import java.util.Map;

/**
 * 作业周期单位
 */
public enum TaskPeriodUnit {

    /**
     * 时
     */
    HOUR(1,"时"),

    /**
     * 日
     */
    DAY(2,"日"),

    /**
     * 周
     */
    WEEK(3,"周"),

    /**
     * 月
     */
    MONTH(4,"月"),

    /**
     * 季
     */
    QUARTER(5,"季"),

    /**
     * 年
     */
    YEAR(6,"年");

    /**
     * 编码
     */
    private Integer value;

    /**
     * 名称
     */
    private String desc;

    private static final Map<Integer, TaskPeriodUnit> stringToEnum = new HashMap<>();

    TaskPeriodUnit(Integer value, String desc){
        this.value = value;
        this.desc = desc;
    }

    static {
        for (TaskPeriodUnit state : TaskPeriodUnit.values()) {
            stringToEnum.put(state.getValue(), state);
        }
    }

    public static TaskPeriodUnit fromString(Integer code) {
        return stringToEnum.get(code);
    }

    public Integer getValue(){
        return value;
    }

    public String getCode(){
        return value.toString();
    }

    public String getDesc(){
        return desc;
    }
}
